package cn.toutatis.filethevoid.controller;


import cn.toutatis.filethevoid.ResultStatus;
import cn.toutatis.filethevoid.utils.FastDFSClientUtil;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfDiv;
import com.itextpdf.text.pdf.PdfWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    FastDFSClientUtil fastDFSClientUtil;

    @RequestMapping(value = "/pdf",method = RequestMethod.GET)
    public Map test() throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(new File("D:\\test.pdf")));
        document.open();
        BaseFont baseFont = BaseFont.createFont( "STSongStd-Light" ,"UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
        Font font = new Font(baseFont, 12,Font.NORMAL);
        Font boldFont = new Font(baseFont, 25,Font.BOLD);
        document.add(new Paragraph("标题测试",boldFont));
        document.add(new Paragraph("中文测试",font));
        document.close();
        return ResultStatus.GET_CACHE_INFO.setResponse();
    }


    @RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
    public void uploadFile(MultipartFile file) throws IOException {
        String uploadFile = fastDFSClientUtil.uploadFile(file);
        System.err.println(uploadFile);
    }
}
